package drive.Controller;

import drive.Model.Second;
import drive.Model.Secondhanditem;
import drive.Service.ServiceInterface.SecondHandItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;

@RestController
@RequestMapping("/secondhanditem")
public class SecondHandItemController {
    @Autowired
    private SecondHandItemService secondHandItemService;

    // 查询所有二手物品
    @GetMapping()
    public String selectAllItems() {
        return secondHandItemService.findAll();
    }

    // 根据itemID查询二手物品
    @GetMapping("/{itemID}")
    public String selectItemByItemID(@PathVariable("itemID") int itemID) {
        return secondHandItemService.findByItemID(itemID);
    }

    // 根据sellerID查询二手物品
    @GetMapping("/seller/{sellerID}")
    public String selectItemsBySellerID(@PathVariable("sellerID") int sellerID) {
        return secondHandItemService.findBySellerID(sellerID);
    }

    // 新增二手物品
    @PostMapping()
    public String addItem(@RequestBody Secondhanditem item) {
        return secondHandItemService.add(item);
    }

    // 更新二手物品
    @PutMapping()
    public String updateItem(@RequestBody Second item) {
        return secondHandItemService.update(item);
    }

    // 删除二手物品
    @DeleteMapping("/{itemID}")
    public String deleteItem(@PathVariable("itemID") int itemID) {
        return secondHandItemService.delete(itemID);
    }
}



